//
//  MainViewController.swift
//  Weibo
//
//  Created by 张文文 on 15/5/27.
//  Copyright (c) 2015年 zww. All rights reserved.
//

import UIKit

class MainViewController: UITabBarController {

    @IBOutlet weak var mainTabBar: MainTabBar!
    override func viewDidLoad() {
        super.viewDidLoad()

        addChildViewControllers()
        
        //直接撰写按钮的监听方法
        
        self.mainTabBar.composedButton.addTarget(self, action: "clickCompose", forControlEvents: UIControlEvents.TouchUpInside)
        
    }
    
    func clickCompose(){
        println("点击了+按钮" + "\(__FUNCTION__)")
    }
    
    ///添加所有子控制器
    private func addChildViewControllers() {
        
        tabBar.tintColor = UIColor.orangeColor()
        
        addChildViewController("Home", "首页", "tabbar_home")
        addChildViewController("Message", "信息", "tabbar_message_center")
        addChildViewController("Discover", "发现", "tabbar_discover")
        addChildViewController("Profile", "我", "tabbar_profile")
        
        
  
    }
    //函数的重载   函数名相同，参数个数及类型不同
    func  addChildViewController(sbName: String, _ title: String, _ imageName: String) {
        let sb = UIStoryboard(name: sbName, bundle: nil)
        
        let nav = sb.instantiateInitialViewController() as! UINavigationController
        
//        nav.title = title
        nav.topViewController.title = title
        
        
        nav.tabBarItem.image = UIImage(named: imageName)
        
        nav.tabBarItem.selectedImage = UIImage(named: imageName + "_highlighted")
        
        addChildViewController(nav)
    
    }

    

}
